//
// Created by mgts on 2016/7/17.
//

#ifndef UHYLABTEST_SCANCOLOR_H
#define UHYLABTEST_SCANCOLOR_H

#include <string.h>
#include <jni.h>
#include <stddef.h>

#include "SquareDetect_API.h"
using namespace std;
// #include "com_example_mgts_jni_ScanColorJNI.h"

struct ColorBlock
{
    ColorBlock(){memset(colorLevel, 0, sizeof(int) * 256);}
    unsigned int colorLevel[256];

    int minR , maxR ;
    int minG , maxG ;
    int minB , maxB ;

    int minH , maxH ;
    int minS , maxS ;
    int minV , maxV ;

    int lightLevel ;
    float ratio;///比值

    int ID ;
};

struct ColorEdit
{
    ColorEdit(){memset(colorLevel, 0, sizeof(int) * 256);}
    int lightLevel ;

    unsigned int colorLevel[256];

    ColorBlock colorBlock[11];
};

class ScanColor {
public:
    void Init(int width, int height,unsigned char * color);
    void UpdatBuff(unsigned char * color, int width, int height, int bit, RecogResult &pRealRes);
   // void UpDataBuff(unsigned char * color, int width, int height, int bit, int x, int y, int id);

    void UpdatRGBBuff(unsigned char * color, int width, int height, int bit);

    JavaVM * javaVM;
    JNIEnv * env;
    jobject jobj;

    jobject javaObject;

    ColorEdit colorEdit;

    unsigned char * rgbBuff;
    void YUV_TO_RGB(unsigned char * yuvColor, int width, int height, unsigned char * rgbColor, int bit);
    void RGB_TO_YUV(unsigned char * rgbColor, int width, int height, int bit, unsigned char * yuvColor);

    void YUV_RGB(unsigned char Y, unsigned char CR, unsigned char CB, unsigned char &R, unsigned char &G, unsigned char&B);
    void RGB_YUV(unsigned char R, unsigned char G, unsigned char B, unsigned char &Y, unsigned char &UR, unsigned char &VB);

    /////////////////////////////////////////

    int GetLightLevel(unsigned char * color, int width, int height, int bit);
    int GetIDBYLightLevel(int id);
    int GetIDBYMaxRGB(int id);

    /////////////////////////////////////////
    void UpDataColorEdit();
};


#endif //UHYLABTEST_SCANCOLOR_H
